package org.zxp.guava;

import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @program: effectiveJava
 * @description: ${description}
 * @author: X-Pacific zhang
 * @create: 2019-05-01 16:52
 **/
public class TestBloomFilter {
    @Test
    public void testMname(){
        List<String> list = Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l");

        BloomFilter<String> bf;
        //创建布隆过滤器(默认3%误差)
        bf = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), list.size());
        list.forEach(s -> bf.put(s));

        list.forEach(s -> System.out.println(bf.mightContain(s)));
        ;
        System.out.println(bf.mightContain("cc"));
    }
}
